using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Windows.Forms;
using Hydrobase;
using HydrobaseSDK;
using TheDarkOwlLogger;
using wow_backtiupCore;

namespace wow_backtiup
{ 
    /// <summary>
    ///  Class that handles the options of the project
    /// </summary>
    class optionsCore
    {
        static TheDarkOwlLogger.TheDarkOwlLogger Bugger = new TheDarkOwlLogger.TheDarkOwlLogger();
        public static string settingDir = SDKBase.ApplicationPreferencesDir;
        public const string generalfile = "General";
        public const string extappinfofile = "External_Applications";
        public static DataSet AppinfoSet = new DataSet();
        public static DataSet GeneralSet = new DataSet();
        public static hydrobaseADO hbado = new hydrobaseADO();
        public static string[] OptGeneralTags, OptextAppsTags;




        public static void Bugtracking(Exception e)
        {
            Program.Bugtracking(e);

        }
        /// <summary>
        /// Creates the settings Files
        /// </summary>
        public static void CreateSettingsFiles()
        {

            try
            {
                // DataSet tmp1= new DataSet();
                //DataSet tmp2= new DataSet();
                //object[] values1, values2;
                //optionsGUI generalGUI;
                if (settingDir != null)
                {

                    OptextAppsTags = Kernel.Appinfocells;
                    if ((File.Exists(settingDir + "\\" + generalfile + BaseClass.default_fileextension) == false) &&
                    (File.Exists(settingDir + "\\" + extappinfofile + BaseClass.default_fileextension) == false) &&(OptGeneralTags!=null) &&(OptextAppsTags!=null))
                    
                    {

                        hbado.TableCreation(settingDir + "\\" + generalfile + BaseClass.default_fileextension, OptGeneralTags, Application.ProductName + " - " + Application.ProductVersion);

                       // MessageBox.Show(OptextAppsTags[0] + "  " + OptGeneralTags[1] + "  " + OptextAppsTags[2]);
                        hbado.TableCreation(settingDir + "\\" + extappinfofile + BaseClass.default_fileextension, Kernel.Appinfocells, Application.ProductName + " - " + Application.ProductVersion);

                       


                    }

                }

            }
            catch (Exception e)
            {
                Bugtracking(e);
            }


        }
        /// <summary>
        /// Loads settings
        /// </summary>
        public static void LoadSettings()
        {
            try
            {
                if (settingDir != null)
                {
                    if ((File.Exists(settingDir + "\\" + generalfile + BaseClass.default_fileextension) == false) || (File.Exists(settingDir + "\\" + optionsCore.extappinfofile  + BaseClass.default_fileextension) == false))
                    {
                        optionsCore.CreateSettingsFiles();
                        //optionsCore.LoadSettings();
                    }
                  //  SecuritySet = new DataSet();
                   
                    
                        GeneralSet = new DataSet();
                        AppinfoSet = new DataSet();
                    hbado.AttachDataBaseinDataSet(GeneralSet, settingDir + "\\" + generalfile + BaseClass.default_fileextension);
                    
                    hbado.AttachDataBaseinDataSet(AppinfoSet, settingDir + "\\" + extappinfofile  + BaseClass.default_fileextension);
                   
                    // hbado.AttachDataBaseinDataSet(SecuritySet, settingDir + "\\" + securityfile + BaseClass.default_fileextension);
                    // this.showValues();
                }
            }
            catch (Exception e)
            {
                Bugtracking(e);

            }

        }
        /// <summary>
        /// Fixing bool valus
        /// </summary>
        /// <param name="value">value to be converted to boolean</param>
        /// <returns>the given value as boolean</returns>

        public static Boolean CheckandFixBooleanValues(object value)
        {

            try
            {
                Boolean ap = false;
                if (value != null)
                {
                    ap = Convert.ToBoolean(value);

                }
                return ap;
            }
            catch (Exception e)
            {
                Bugtracking(e);
                return false;
            }


        }
        /// <summary>
        /// Converts boolean to string and returns it 
        /// </summary>
        /// <param name="val">bool value to be converted to string</param>
        /// <returns>the string value of the given bool </returns>
        public static string BoolToString(bool val)
        {
            try
            {
                string  ap = null;
                if (val != null)
                {
                    ap = Convert.ToString(val);

                }
                return ap;
            }
            catch (Exception e)
            {
                Bugtracking(e);
                return null;
            }


        }
        
    }
}
